<template>
	
	<div class="search-box" style="padding:0">
	  <a-form layout="vertical" style="display:flex;opacity:0;height:0">
		
		
		
		<a-form-item label="文章发布时间" style="margin-right:8px">
		  <a-range-picker v-model:value="formparams.time" value-format="YYYY-MM-DD" format="YYYY-MM-DD" />
		  </a-form-item>
		   <a-form-item class="no-content-label" label=".">
		       <a-button type="primary" @click="getDataList('new')" html-type="submit">查询</a-button>
		     </a-form-item>
		 
	  </a-form>
	  
	  <a-button style="top:0;margin-bottom:5px;right:60px"  class="add-right" @click="addlistdata({})" type="primary" html-type="submit">新增</a-button>
	</div>
	
	<!-- <div class="search-box">
		<a-row justify="space-between" style="width:100%">
		    <a-form layout="inline"  model="horizontal" >
			11
				
		    </a-form>
			<div class="right-btns">
				<a-button  @click="addlistdata">新增</a-button>
				
			</div>
		</a-row>
		
	</div> -->
	
	
	<a-tabs
	  v-model:activeKey="activeKey"
	  tab-position="left"
	  :style="{ height: '100%' }"
	  @change="callback"
	>
	  <a-tab-pane v-for="(item,index) in zeroList" :key="item.explaind" :tab="item.dataName">
		 <a-table
		 style="margin-right:30px"
		   :columns="columns"
		 	:pagination="false"
		   :data-source="tableData"
		 >
		 	<template #emptyText>
		 		未查到相关记录,请添加
		 	</template>
		  <template #bodyCell="{ column,record  }">
		 	   
		       <template v-if="column.dataIndex == 'action'">
		         <div class="operation-wrap" >
		 		
		 			<div class="table-edit-btn" style="margin-right:6px"  @click="detailClick(record,2)">
		 				编辑
		 			</div> 
		 			<a-popconfirm @confirm="confirmDel(record)" title="确定删除？" ok-text="确定" cancel-text="取消">
		 			    <div class="table-del-btn">
		 			    	删除
		 			    </div> 
		 			</a-popconfirm>
		 			
		 		  </div>
		       </template>
		 		<template v-if="column.dataIndex == 'status'">
		 		  <div class="operation-wrap" >
		 		
		 			<a-switch v-model:checked="record.statusshow" />
		 		
		 			
		 		  </div>
		 		</template>
		     </template>
		 </a-table>
	  </a-tab-pane>
	</a-tabs>
	
	
	
	
	
	
	
	
	
	
	
	
	
	
 
  <a-modal
  width="640px"
    :footer="null"
	:destroyOnClose="true"
	v-model:visible="visible"
	:title="logtitle"
	@ok="handleOk"
  > 
    
  <a-form
	
    :model="addForm"
    ref="formRef"
	layout="vertical"
    name="addForm"
   
    autocomplete="off"
    >
	
		<a-row justify="space-between" style="margin-bottom:12px">
			<a-col :span="11">
				<a-form-item
				:colon="true"
				  label="字段名"
				  name="dataName"
				  :rules="[{ required: true, message: '字段名' }]"
				>
				  <a-input  placeholder="字段名" v-model:value="addForm.dataName" />
				</a-form-item>
			</a-col>
			<a-col :span="11">
				<a-form-item
				  label="字段值"
				  name="explaind"
				  :rules="[{ required: true, message: '字段值' }]"
				>
				  <a-input placeholder="字段值" v-model:value="addForm.explaind" />
				</a-form-item>
			</a-col>
			<a-col :span="11">
				<a-form-item
				  label="类型"
				  name="type"
				  :rules="[{ required: true, message: '类型' }]"
				>
					<a-select
						:options="zeroList"
						style="width:100%"
						:fieldNames="{ label: 'dataName', value: 'explaind' }"
						placeholder="类型"  v-model:value="addForm.type">
											
					</a-select>
					
					
					
				 
				</a-form-item>
			</a-col>
			<a-col :span="11">
				<a-form-item style="width:100%" :rules="[{ required: true, message: '排序' }]"  label="排序" name="sort">
				    <a-input-number placeholder="排序" style="width:100%" v-model:value="addForm.sort" />
				</a-form-item>
			</a-col>
			<!-- <a-col :span="6">
				<a-form-item
				  label="权限分类"
				  name="spareField2"
				  :rules="[{ required: true, message: '权限分类' }]"
				>
					<a-select
				  
					placeholder="权限分类" style="width:100%" v-model:value="addForm.spareField2">
					
					<a-select-option :value="1">印章</a-select-option>
					<a-select-option :value="2">会议室申请</a-select-option>
					<a-select-option :value="3">发文</a-select-option>
					<a-select-option :value="4">收文</a-select-option>
					<a-select-option :value="5">工作通报</a-select-option>
					<a-select-option :value="6">挂靠单位发文</a-select-option>
					<a-select-option :value="7">信息发布</a-select-option>
				   
				   </a-select>
				 
				</a-form-item>
			</a-col> -->
			<!-- <a-col :span="11">
				<a-form-item
				  label="状态"
				  name="status"
				  :rules="[{ required: true, message: '状态' }]"
				>
					<a-select
				  
					placeholder="状态" style="width:100%" v-model:value="addForm.status">
					
					<a-select-option :value="1">启用</a-select-option>
					<a-select-option :value="2">禁用</a-select-option>
					
				   </a-select>
				  
				</a-form-item>
			</a-col> -->
		</a-row>
		
		
		
		
    </a-form>
  
  
  

  
  <a-row justify="center" class="reset-dialog-footer" >
	<div class="submit-btn" @click="storeClick">
		提交
	</div>
  </a-row>
 
  </a-modal>
  
  
</template>
<script>

import {slxhapisystemdictgetDict,
slxhapisystemdictfrozenDict,
slxhapisystemdicteditDict,

slxhapisystemdictaddDict} from '../../../api/manpart.js'
import { computed,ref, defineComponent,reactive,onMounted } from 'vue';

const columns = [
 
  {
    title: '字段名',
    dataIndex: 'dataName',
    
  },
  {
    title: '字段值',
    dataIndex: 'explaind',
    
  },
  {
    title: '排序',
    dataIndex: 'sort',
    
  },
 
  
  // {
  //   title: '类型',
  //   dataIndex: 'typeshow'
  // },
 
  {
    title: '操作',
    dataIndex: 'action',
	width:'140px'
  }
];


function getSpare(type){
	let str=''
	switch(Number(type)){
		
		case 1:
			
			str='印章'
		break;
		case 2:
			
			str='会议室申请'
		break;
		case 3:
			
			str='发文'
		break;
		case 4:
			
			str='收文'
		break;
		case 5:
			
			str='工作通报'
		break;
		case 6:
			
			str='挂靠单位发文'
		break;
		case 7:
			
			str='信息发布'
		break;
		
	}
	
	return str
}



function gettype(type){
	let str=''
	switch(Number(type)){
		
		case 1:
			
			str='用户权限'
		break;
		case 2:
			
			str='用户岗位'
		break;
		case 3:
			
			str='用户角色'
		break;
		
	}
	
	return str
}



export default defineComponent({
  setup() {
	  let logtitle=ref('')
	  let initAddForm={
			  type:null,
			  
			  status:1,
			  sort:1,
			  explaind:'',
			  dataName:'',
			  level:''
		}
	  let isshow=ref(false)
	  let tableData=ref([])
	  let formRef=ref()
	  let addForm=reactive({
			  type:null,
			  
			  status:1,
			  sort:1,
			  explaind:'',
			  dataName:'',
			  level:''
		})
	  let visible=ref(false)
	let layout={
		labelCol: { span: 4 },
		wrapperCol: { span: 14 }
	}
	let formparams=reactive({
		type:1,
		categoryName:'',
		manageDeptName:''
	})
	const getData=()=>{
		slxhapisystemdictgetDict(formparams).then(e=>{
			tableData.value=e.object.map(item=>{
				item.statusshow=item.status==1
				item.typeshow=gettype(item.type)
				item.spareField2show=getSpare(item.spareField2)
				return item
			})
		}).catch(err=>{
			console.log(err)
		})
	}
	
	let zeroList=ref([])
	
	const getTypeZero=()=>{
		slxhapisystemdictgetDict({type:0}).then(e=>{
			zeroList.value=e.object.map(item=>{
				item.explaind=Number(item.explaind)
				return item
			})
			zeroList.value.push({
				explaind:0,
				dataName:'数据字典类型'
			})
		}).catch(err=>{
			console.log(err)
		})
	}
	
	const addlistdata=()=>{
		logtitle.value="增加数据字典"
		for(let key in initAddForm){
			addForm[key]=initAddForm[key]
		}
		
		visible.value=true
	}
	let depList=ref([])

	onMounted(()=>{
		getData()
		getTypeZero()
		
		
	})
	const freez=()=>{
		slxhapisystemdictfrozenDict({
			code:'DICT-1168561564'
		}).then(e=>{
			console.log(e)
		}).catch(err=>{
			console.log(err)
		})
	}
	const editdata=()=>{
		let transData=JSON.parse(JSON.stringify(addForm))
		slxhapisystemdicteditDict(transData).then(e=>{
			for(let key in addForm){
				addForm[key]=null
			}
			
			addForm.status=1
			addForm.sort=1
			visible.value=false
			getData()
			getTypeZero()
			globalVar.Message.success('操作成功')
		}).catch(err=>{
			console.log(err)
		})
	}
	
	const storeClick=()=>{
		
		formRef.value
		.validate()
		.then(() => {
			let transData=JSON.parse(JSON.stringify(addForm))
			if(transData.dataCode){
				editdata()
				return
			}
			slxhapisystemdictaddDict(transData).then(e=>{
				if(e.code==1){
					for(let key in addForm){
						addForm[key]=null
					}
					
					addForm.status=1
					addForm.sort=1
					visible.value=false
					getData()
					getTypeZero()
					globalVar.Message.success('操作成功')
				}else{
					globalVar.Message.warning(e.message)
				}
			}).catch(err=>{
				console.log(err)
			})
		})
		.catch((error) => {
		  console.log("error", error);
		});
		
	}
	
	
	const detailClick=(item,type)=>{
		isshow.value=type==1?true:false
		logtitle.value="编辑数据字典"
		for(let key in item){
			addForm[key]=item[key]
		}
		visible.value=true
	}
	
	const confirmDel=item=>{
		
		slxhapisystemdictfrozenDict({
			code:item.dataCode
		}).then(e=>{
			if(e.code==1){
				getData()
				getTypeZero()
				globalVar.Message.success('操作成功')
			}else{
				globalVar.Message.warning(e.message)
			}
			
		}).catch(err=>{
			console.log(err)
		})
		
		
		
	}
	
	
	let activeKey=ref(1)
	const callback=val=>{
		formparams.type=val
		getData()
	}
	const routes = ref([
	     {
	       path: 'dataword',
	       breadcrumbName: '数据字典',
	     }
	   ]);
    return {
		routes,
		callback,
		activeKey,
		logtitle,
		zeroList,
		getData,
		isshow,
		detailClick,
		confirmDel,
		depList,
		storeClick,
		formRef,
		addForm,
		addlistdata,
		visible,
		layout,
		formparams,
		tableData,
		columns
    };
  }
});
</script>



<style>
	.search-box{
		padding:20px 0;
	}
</style>

